package cn.tedu.cwfw.pet.controller;

import cn.tedu.cwfw.base.response.JsonResult;
import cn.tedu.cwfw.pet.pojo.dto.PetSaveParam;
import cn.tedu.cwfw.pet.pojo.vo.PetVO;
import cn.tedu.cwfw.pet.service.PetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cwfw/pet")
@Slf4j
public class PetController {
    @Autowired
    PetService petService;

//    添加宠物
    @PostMapping("insert")
    public JsonResult insert(PetSaveParam petSaveParam){
        log.debug("添加宠物信息:{}", petSaveParam);
        petService.insert(petSaveParam);
        return JsonResult.ok();
    }
//    删除宠物
    @PostMapping("delete")
    public JsonResult delete(Long id){
        log.debug("删除宠物:{}",id);
        petService.delete(id);
        return JsonResult.ok();
    }
//   修改宠物信息
    @PostMapping("update")
    public JsonResult update(PetSaveParam petSaveParam){
        log.debug("修改宠物信息:{}",petSaveParam);
        petService.update(petSaveParam);
        return JsonResult.ok();
    }
//  查看用户的所有宠物
    @PostMapping("findPet")
    public JsonResult findPet(Long clientId){
        log.debug("查看用户的所有宠物:{}",clientId);
        List<PetVO> petVOS = petService.findPet(clientId);
        return JsonResult.ok(petVOS);
    }
//    查看某个宠物信息
    @PostMapping("findById")
    public JsonResult findById(Long id){
        log.debug("查看某个宠物信息:{}",id);
        PetVO petVO = petService.findById(id);
        return JsonResult.ok(petVO);
    }
}
